/**
 * 数字小于10 前面补0
 * @param {*} value 传入数字
 * @returns 
 */
export function addPreZero(value) {
  let valueInt = parseInt(value)
  if(valueInt >= 10) {
    return valueInt + ''
  } else {
    return '0' + valueInt
  }
}
/**
 * 日期格式化
 * @param {*} date 传入日期
 * @param {*} formate 日期格式
 * @returns 
 */
export function timeParse(date, formate="yyyy-MM-dd HH:mm:ss") {
  let dates = new Date(date)
  let years = dates.getFullYear()
  let months = dates.getMonth() + 1
  let days = dates.getDate()
  let hours = dates.getHours()
  let minutes = dates.getMinutes()
  let seconds = dates.getMinutes()

  let datetime = formate.replace('yyyy', years).replace('MM', addPreZero(months)).replace('dd', addPreZero(days)).replace('HH', addPreZero(hours)).replace('mm', addPreZero(minutes)).replace('ss', addPreZero(seconds))
  return datetime
}
/**
 * 获取当前日期月份天数
 * @param {*} date 
 * @returns 
 */
export function timeDaysOfMonth (date=new Date()) {
  let time = new Date(date) 
  let month = time.getMonth()
  time.setMonth(month + 1)
  time.setDate(0)
  return time.getDate()
}